define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/physical_exam_package/index' + location.search,
                    add_url: 'vppz/physical_exam_package/add',
                    edit_url: 'vppz/physical_exam_package/edit',
                    del_url: 'vppz/physical_exam_package/del',
                    multi_url: 'vppz/physical_exam_package/multi',
                    table: 'vppz_examination_package',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'name', title: '名称', operate: 'LIKE'},
                        {field: 'cate_id', title: '套餐类型',formatter: function(value, row, index) {
                                const genderMap = {'bijian': '必检套餐', 'multi': '组合套餐', 'auto': '自选套餐'};
                                return genderMap[value] || '组合套餐';
                            },
                            // 筛选配置
                            searchList: {
                                'bijian': '必检套餐',
                                'multi': '组合套餐',
                                'auto': '自选套餐'
                            },
                            // 筛选操作符（等于）
                            operate: '=',custom:{'bijian':'warning','multi':'info','auto':'success'}},
                        {field: 'hospital_name', title: '体检医院', operate: 'LIKE'},
                        {field: 'total_original_price', title: '总价', operate: 'BETWEEN'},
                        {field: 'total_discount', title: '总优惠', operate: 'BETWEEN'},
                        {field: 'final_price', title: '最终价', operate: 'BETWEEN'},
                        {field: 'people_type', title: '试用人群', operate: 'LIKE'},
                        {field: 'is_active', title: '是否启用', table: table, formatter: Table.api.formatter.toggle,searchable:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                        buttons: [{
                                    name: 'physical_item',
                                    title: '体检项目',
									text: '体检项目',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/physical_item_rel/index',
                                    //callback: function (data) {
                                    //    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    //}
                                }]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
